<?php
include_once ('db_manage.php');

function getSearchTravel($search_key, $page, $num_row_of_page, $hot, $date) {
	$start = $page * $num_row_of_page;
	$data = array ();
	$sql = "select t.*,(select username from uc_members m where t.postuser = m.uid) as username from pcd_travel t where t.title like '%" . $search_key . "%'";
	
	if ($hot == 1) {
		$hot_sql = " order by hot";
		$sql = $sql . $hot_sql;
	} else if ($hot == 0) {
		$hot_sql = " order by hot desc ";
		$sql = $sql . $hot_sql;
	}
	
	if ($date == 1) {
		$date_sql = " order by id";
		$sql = $sql . $date_sql;
	} else if ($date == 0) {
		$date_sql = " order by id desc ";
		$sql = $sql . $date_sql;
	}

	$sql = $sql . " limit " . $start . "," . $num_row_of_page;
	
	$result = mysql_query ( $sql );
	
	while ( ($row = mysql_fetch_array ( $result, MYSQL_ASSOC )) != false ) {
		$array = array ();
		$array ['id'] = $row ['id'];
		if ($row ['id'] == $row ['fid']) {
			$array ['module'] = "travel";
		} else {
			$array ['module'] = "scence";
		}
		$array ['title'] = $row ['title'];
		$array ['postuser'] = $row ['postuser'];
		$array ['postdate'] = $row ['timestamp'];
		$array ['username'] = $row ['username'];
		$array ['content'] = $row ['content'];
		$array ['hot'] = $row ['hot'];
		array_push ( $data, $array );
	}
	mysql_free_result ( $result );
	return $data;
}

function getSearchTravelCount($search_key) {
	$sql = "select t.*,(select username from uc_members m where t.postuser = m.uid) as username from pcd_travel t where t.title like '%" . $search_key . "%'";
	$result = mysql_query ( $sql );
	return mysql_num_rows ( $result );
}

function getSearchPlay($search_key, $page, $num_row_of_page, $hot, $date) {
	$start = $page * $num_row_of_page;
	$data = array ();
	$sql = "select p.*,(select username from uc_members m where p.postuser = m.uid) as username from pcd_play_info_2 p where p.playname  like '%" . $search_key . "%'";
	
	if ($hot == 1) {
		$hot_sql = " order by playhot";
		$sql = $sql . $hot_sql;
	} else if ($hot == 0) {
		$hot_sql = " order by playhot desc ";
		$sql = $sql . $hot_sql;
	}
	
	if ($date == 1) {
		$date_sql = " order by playid";
		$sql = $sql . $date_sql;
	} else if ($date == 0) {
		$date_sql = " order by playid desc ";
		$sql = $sql . $date_sql;
	}
	
	$sql = $sql . " limit " . $start . "," . $num_row_of_page;
	
	$result = mysql_query ( $sql );
	while ( ($row = mysql_fetch_array ( $result, MYSQL_ASSOC )) != false ) {
		$array = array ();
		$array ['id'] = $row ['playid'];
		$array ['module'] = "play";
		$array ['title'] = $row ['playname'];
		$array ['postuser'] = $row ['postuser'];
		$array ['postdate'] = $row ['timestamp'];
		$array ['username'] = $row ['username'];
		$array ['content'] = $row ['playdetail'];
		$array ['hot'] = $row ['playhot'];
		array_push ( $data, $array );
	}
	mysql_free_result ( $result );
	return $data;
}

function getSearchPlayCount($search_key) {
	$sql = "select p.*,(select username from uc_members m where p.postuser = m.uid) as username from pcd_play_info_2 p where p.playname  like '%" . $search_key . "%'";
	$result = mysql_query ( $sql );
	return mysql_num_rows ( $result );
}

function getSearchRoute($search_key, $page, $num_row_of_page, $hot, $date) {
	$start = $page * $num_row_of_page;
	$data = array ();
	$sql = "select r.*,(select username from uc_members m where r.postuser = m.uid) as username from pcd_route r where r.title  like '%" . $search_key . "%'";
	
	if ($hot == 1) {
		$hot_sql = " order by hot";
		$sql = $sql . $hot_sql;
	} else if ($hot == 0) {
		$hot_sql = " order by hot desc ";
		$sql = $sql . $hot_sql;
	}
	
	if ($date == 1) {
		$date_sql = " order by rid";
		$sql = $sql . $date_sql;
	} else if ($date == 0) {
		$date_sql = " order by rid desc ";
		$sql = $sql . $date_sql;
	}
	
	$sql = $sql . " limit " . $start . "," . $num_row_of_page;
	
	$result = mysql_query ( $sql );
	while ( ($row = mysql_fetch_array ( $result, MYSQL_ASSOC )) != false ) {
		$array = array ();
		$array ['id'] = $row ['id'];
		$array ['module'] = "route";
		$array ['title'] = $row ['title'];
		$array ['postuser'] = $row ['postuser'];
		$array ['postdate'] = $row ['timestamp'];
		$array ['username'] = $row ['username'];
		$array ['content'] = $row ['content'];
		$array ['hot'] = $row ['hot'];
		array_push ( $data, $array );
	}
	mysql_free_result ( $result );
	return $data;
}

function getSearchRouteCount($search_key) {
	$sql = "select r.*,(select username from uc_members m where r.postuser = m.uid) as username from pcd_route r where r.title  like '%" . $search_key . "%'";
	$result = mysql_query ( $sql );
	return mysql_num_rows ( $result );
}

function getSearchNews($search_key, $page, $num_row_of_page, $hot, $date) {
	$start = $page * $num_row_of_page;
	$data = array ();
	$sql = "select r.*,(select username from uc_members m where r.postuser = m.uid) as username from pcd_news r where r.title  like '%" . $search_key . "%'";
	if ($hot == 1) {
		$hot_sql = " order by hot";
		$sql = $sql . $hot_sql;
	} else if ($hot == 0) {
		$hot_sql = " order by hot desc ";
		$sql = $sql . $hot_sql;
	}
	
	if ($date == 1) {
		$date_sql = " order by id";
		$sql = $sql . $date_sql;
	} else if ($date == 0) {
		$date_sql = " order by id desc ";
		$sql = $sql . $date_sql;
	}

	$sql = $sql . " limit " . $start . "," . $num_row_of_page;
	$result = mysql_query ( $sql );
	while ( ($row = mysql_fetch_array ( $result, MYSQL_ASSOC )) != false ) {
		$array = array ();
		$array ['id'] = $row ['id'];
		$array ['module'] = "news";
		$array ['title'] = $row ['title'];
		$array ['postuser'] = $row ['postuser'];
		$array ['postdate'] = $row ['postdate'];
		$array ['username'] = $row ['username'];
		$array ['content'] = $row ['content'];
		$array ['hot'] = $row ['hot'];
		array_push ( $data, $array );
	}
	mysql_free_result ( $result );
	return $data;
}

function getSearchNewsCount($search_key) {
	$sql = "select r.*,(select username from uc_members m where r.postuser = m.uid) as username from pcd_news r where r.title  like '%" . $search_key . "%'";
	$result = mysql_query ( $sql );
	return mysql_num_rows ( $result );
}
?>